package com.skeeey.aim.model.statistics;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.skeeey.aim.model.AutoRecord;
import com.skeeey.aim.model.Dealer;

public class StatisticRecord {
	private Dealer dealer;
	private Date createDate;
	private String userName;
	private Map<Integer, List<AutoRecord>> records = new HashMap<Integer, List<AutoRecord>>();
	
	public StatisticRecord(Dealer dealer) {
		this.dealer = dealer;
		for(int i = 0; i < 7; i++) {
			records.put(Integer.valueOf(0), new ArrayList<AutoRecord>());
		}
	}
	
	public void addRecord(int index, AutoRecord newRecord) {
		List<AutoRecord> autoRecords = records.get(Integer.valueOf(index));
		AutoRecord removedRecord = null;
		for(AutoRecord ar : autoRecords) {
			if(ar.getId().equals(newRecord.getId())) {
				removedRecord = ar;
				break;
			}
		}
		if(removedRecord != null) {
			autoRecords.remove(removedRecord);
		}
		autoRecords.add(newRecord);
	}
	
	public void putRecords(int index, List<AutoRecord> records) {
		this.records.put(Integer.valueOf(index), records);
	}
	
	public List<AutoRecord> getRecordsBy(int index) {
		return records.get(Integer.valueOf(index));
	}
	
	public Date getCreateDate() {
		return createDate;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserName() {
		return userName;
	}

	public Dealer getDealer() {
		return this.dealer;
	}
}
